<?php
class Model_Package extends Core_Database
{
    /**
     * Lay danh sach tat ca cac goi dich vu
     * @param: void
     * @return : array(): neu co it nhat mot package  null: neu khong co package nao
     * 
     * */
    public function getPackages()
    {
     $sql = 'select * from package';
     $sth = $this->_db->prepare($sql);
     $status = $sth->execute();
     if (!$status)
          return null;
     $result = $sth->fetchAll();
     if(count($result)>0)
        return $result;
     else
        return null;   
    }
    
 	/**
    * Lay thong tin cua mot goi dich vu
    * 
    * @param : package_id
    * @return : array : neu ton tai  null : neu khong ton tai
    * 
    */
    public function getPackage($package_id)
    {
     $sql = 'select * from package where package_id = :package_id';
     $sth = $this->_db->prepare($sql);
     $sth->bindParam(':package_id',$package_id,PDO::PARAM_INT);
     $status = $sth->execute();
     if (!$status)
          return null;
     $result = $sth->fetchAll();
     if(count($result)>0)
        return $result;
     else
        return null;     
    }
    
 	/**
     * Lay danh sach tat ca cac goi dich vu + template
     * @param: void
     * @return : array(): neu co it nhat mot package  null: neu khong co package nao
     * 
     */
    public function getPackages_Templates()
    {
     $sql = 'select package.* from package,template where package.template_id = template.template_id ';
     $sth = $this->_db->prepare($sql);
     $status = $sth->execute();
     if (!$status)
          return null;
     $result = $sth->fetchAll();
     if(count($result)>0)
        return $result;
     else
        return null;   
    }
    
 	/**
    * Lay thong tin cua mot goi dich vu + template_path
    * 
    * @param : package_id
    * @return : array : neu ton tai  null : neu khong ton tai
    * 
    * */
    public function getPackage_Template($package_id)
    {
     $sql = 'select package.*,template_path from package,template where package_id = :package_id and package.template_id = template.template_id';
     $sth = $this->_db->prepare($sql);
     $sth->bindParam(':package_id',$package_id,PDO::PARAM_INT);
     $status = $sth->execute();
     if (!$status)
          return null;
     $result = $sth->fetchAll();
     if(count($result)>0)
        return $result;
     else
        return null;     
    }
}    